<template>
  <PageWrapper dense contentFullHeight fixedHeight contentClass="flex">
    <BasicTable @register="registerTable">
      <template #toolbar>
        <button class="button" @click="Deletelog()">删除日志</button>
      </template>
    </BasicTable>
  </PageWrapper>
</template>
<script lang="ts" setup name="Dict">
import { PageWrapper } from "@/components/Page";
import { BasicTable, useTable } from "@/components/Table";
import { loginColumns, loginsearchFormSchema } from "./log.data";
import { useI18n } from '@/hooks/web/useI18n';
import { GetLoginLogList, DeleteLoginLog } from "@/api/log/log";
import { notification } from "ant-design-vue";
import { useMessage } from "@/hooks/web/useMessage";
const { t } = useI18n();
const [registerTable, { reload }] = useTable({
  title: '登录日志列表',
  api: GetLoginLogList,
  columns:loginColumns,
  formConfig: {
    labelWidth: 120,
    schemas: loginsearchFormSchema,
  },
  beforeFetch: (params) => {
    if(params.date != undefined){
      params.startTime = params.date[0] ? params.date[0] : '';
      params.endTime = params.date[1] ? params.date[1] : '';
      delete params.date;
    }
    return params;
  },
  handleSearchInfoFn: (data) => {
    if(data.date != undefined){
      data.startTime = data.date[0] ? data.date[0] : '';
      data.endTime = data.date[1] ? data.date[1] : '';
    }
    return data;
  },
  useSearchForm: true,
  showTableSetting: true,
  bordered: true,
  showIndexColumn: false,
});
const {
  createConfirm,
} = useMessage();
function Deletelog(){
  createConfirm({
    iconType: 'warning',
    title: '删除日志',
    content: '确定删除所有日志吗？只会删除六个月以前日志！',
    onOk: async () => {
      const res = await DeleteLoginLog();
      if (res.code === 200) {
        notification.success({
          message: t('sys.delete.success'),
          description: res.message,
          duration: 3,
        });
        await reload();
      }else{
        notification.error({
          message: t('sys.delete.fail'),
          description: res.message,
          duration: 3,
        });
      }
    },
  });
}
</script>
<style lang="scss" scoped>
.button{
  width: 120px;
  height: 35px;
  background: linear-gradient(to right, rgb(66, 83, 216), rgb(30, 50, 186));
  border-radius: 10px;
  box-shadow: 5px 10px 10px rgba(197, 194, 194, 0.8);
  color: #fff;
  cursor:pointer;
}
.button:hover{
  background: linear-gradient(to right, rgb(30, 50, 186), rgb(66, 83, 216));
}
</style>
